package main

import (
	"encoding/json"
	"fmt"
	"gorm.io/driver/mysql"

	// "http"

	_ "gorm.io/driver/mysql"
	"gorm.io/gorm"
	"unsafe"
)

type animal interface {
	run()
}

type dog struct {
	name string
}

type cat struct {
	name string
}

func (a dog) run() {
	fmt.Println("dog wolf " + a.name)
	a.name += " modify"
}

func (a cat) run() {
	fmt.Println("cat mow  " + a.name)
	a.name += " modify"
}

// func (a *dog)run()  {
// 	fmt.Println("dog wolf "+a.name)
// 	a.name+=" modify"
// }

// func (a *cat)run()  {
// 	fmt.Println("cat mow  "+a.name)
// 	a.name+=" modify"
// }

func run(a animal) {
	a.run()
}

func TestIfce() {
	c := &cat{"haha"}
	d := &dog{"xixi"}
	run(c)
	run(d)
	run(c)
	run(d)
}

func Bytes2String(b []byte) string {
	return *(*string)(unsafe.Pointer(&b))
}

type Member struct {
	// gorm.Model
	Id                 int
	Name               string `gorm:"column:name"`
	DatachangeLasttime string
}

func main() {
	// file, _ := os.Open("C:\\Users\\taofu\\Desktop\\CinemaOnline.md")
	// info, _ := file.Stat()
	// fmt.Println(info.Size())
	db, err := gorm.Open(mysql.Open("test:123pop@(taofoo.top:3306)/test?charset=utf8&parseTime=True&loc=Local"))
	if err != nil {
		fmt.Println(err)
		return
	}


	db.AutoMigrate(&Member{})

	var ux []Member
	db.Debug().Raw("select * from member_info;").Find(&ux)
	fmt.Printf("user: %v\n", ux)

	var results []map[string]interface{}
	table := db.Debug().Raw("select 1 as sss")
	table.Find(&results)
	//marshal, _ := json.Marshal(results)
	fmt.Printf(ToJsonStr(results))

}

func ToJsonStr(obj interface{}) string {
	marshal, err := json.Marshal(obj)
	if err!=nil{
		panic(err)
	}
	return string(marshal)
}
